/* eslint-disable no-unused-vars,no-undef */
// import { saveTransCusInfo } from '@/api/bankBiz/loss/loss'

/**
 * 随路数据处理接口
 */
var globalUserData = {

  /*************************************************************************************************
   *************************************** 接收事件初始化 ********************************************
   ************************************************************************************************/

  postMessageHandler: function (message) {
    
    console.log("接收到的event=", message.event);

    if (globalEvent.EventCallRecordChange === message.event) {
      let etsFrame = document.getElementById('ets-create-frame')
      if (etsFrame) {
        etsFrame.contentWindow.postMessage(message, '*')
      }
      Constants.Model = {}
      sessionStorage.removeItem('accName')
      sessionStorage.removeItem('bankNo')
      sessionStorage.removeItem('openBankName')
      sessionStorage.removeItem('bankNoList')
      sessionStorage.removeItem('customerNo')
      sessionStorage.removeItem('customerIdType')
      sessionStorage.removeItem('customerIdNo')
      sessionStorage.removeItem('customerPhone')
      Constants.Model = message.data
      window.eventEmitter.$emit('EventCallRecordChange', message.data)
    }
    else if (globalEvent.EventCustomerQuery === message.event) {
      console.log('测试传递工单客户信息')
      window.eventEmitter.$emit('EventChatRecordChange', message.data)

    }
    else if (globalEvent.EventChatRecordChange === message.event) {
      let etsFrame = document.getElementById('ets-create-frame')
      if (etsFrame) {
        etsFrame.contentWindow.postMessage(message, '*')
      }
      if ('video' == message.data.chatType || 'xiaochengxu' == message.data.chatType || !'ChatDone' == message.data.chatState) {
        Constants.ModelChat = message.data
      }
      window.eventEmitter.$emit('EventChatRecordChange', message.data)
    }
    // 注意：这个是处理结束事件
    else if (globalEvent.EventChatDone === message.event) {
      let etsFrame = document.getElementById('ets-create-frame')
      if (etsFrame) {
        etsFrame.contentWindow.postMessage(message, '*')
      }
      window.eventEmitter.$emit('EventChatDone')
    }
    else if (globalEvent.EventCallReleased === message.event) {
      let etsFrame = document.getElementById('ets-create-frame')
      if (etsFrame) {
        etsFrame.contentWindow.postMessage(message, '*')
      }
      window.eventEmitter.$emit('EventCallReleased')
    }
    else if (globalEvent.EventAfterCall === message.event) {
      let etsFrame = document.getElementById('ets-create-frame')
      if (etsFrame) {
        etsFrame.contentWindow.postMessage(message, '*')
      }
      if (Constants.Model.sid == message.data.sid) {
        window.eventEmitter.$emit('EventAfterCall')
        window.eventEmitter.$emit('EventInfoReset')
      }
    }
    // 注意：这个是chatDone事件
    else if ('callEnd' === message.event) {
      let etsFrame = document.getElementById('ets-create-frame')
      if (etsFrame) {
        etsFrame.contentWindow.postMessage(message, '*')
      }
      if (Constants.ModelChat.sid == message.data.sessionId && ('video' == message.data.type || 'xiaochengxu' == message.data.type)) {
        window.eventEmitter.$emit('EventVideoChatDone')
      }
      window.eventEmitter.$emit('EventCallEnd')
    }
    else if (globalEvent.EventAgentStatusChanged === message.event) {
      let etsFrame = document.getElementById('ets-create-frame')
      if (etsFrame) {
        etsFrame.contentWindow.postMessage(message, '*')
      }
      window.eventEmitter.$emit('AgentStatusChanged')
    }
    else if (globalEvent.EventAgentLogout === message.event) {
      let etsFrame = document.getElementById('ets-create-frame')
      if (etsFrame) {
        etsFrame.contentWindow.postMessage(message, '*')
      }
      window.eventEmitter.$emit('EventAgentLogout')
    }
    else if (globalEvent.EventAgentInfo === message.event) {
      let etsFrame = document.getElementById('ets-create-frame')
      if (etsFrame) {
        etsFrame.contentWindow.postMessage(message, '*')
      }
      Constants.Agent = message.data.agentInfo
      Constants.Agent.access_token = message.data.access_token
      $('#kbp-frame').attr('src', window.CONFIG.kbp.createIndexPage + '?access_token=' + Constants.Agent.access_token)
      let roles = ''
      let auth = ''
      for (let i = 0; i < Constants.Agent.role.length; i++) {
        roles += Constants.Agent.role[i] + ','
      }
      roles = roles.substring(0, roles.length - 1)
      let item = Constants.Agent.resources.split(',')
      for (let i = 0; i < item.length; i++) {
        if ('Kbp' == item[i].substring(item[i].length - 3, item[i].length)) {
          auth += item[i] + ','
        }
      }
      auth = auth.substring(0, auth.length - 1)
      // 租户+用户+角色+部门+权限
      Constants.userToken = Constants.Agent.tenantId + '&' + Constants.Agent.userId + '&' + roles + '&' + Constants.Agent.deptGroupCode + '&viewAllKbp'
      console.log('user-token is: ' + Constants.userToken)
      window.eventEmitter.$emit('EventAgentInfo', Constants.Agent)
    }
    else if (globalEvent.EventAccessToken === message.event) {
      if (message.data.access_token) {
        $('#kbp-frame').attr('src', window.CONFIG.kbp.createIndexPage + '?access_token=' + message.data.access_token)
      }
    }
    else if ('createWorkOrderFromSummary' === message.event) {
      let etsFrame = document.getElementById('ets-create-frame')
      if (etsFrame) {
        etsFrame.contentWindow.postMessage(message, '*')
      }
      window.eventEmitter.$emit('createWorkOrderFromSummary')
    }
    else if ('InterctClientInfo' === message.event) {
      let etsFrame = document.getElementById('ets-create-frame')
      if (etsFrame) {
        etsFrame.contentWindow.postMessage(message, '*')
      }
      window.eventEmitter.$emit('InterctClientInfo')
    }
    // 验密结果
    else if ('EventVerifyResult' === message.event) {
      let data = message.data
      console.log(JSON.stringify(data))
      // 验密标识
      let verifyFlag = data.i_verifyflag
      if ('01' == verifyFlag) {
        Constants.Model.userData = data
        window.eventEmitter.$emit('EventVerifyResult', data)
      } else if ('06' == verifyFlag) {
        // 短信银行业务
        if (('01' == data.p_biz || '02' == data.p_biz || '03' == data.p_biz || '04' == data.p_biz) && '01' == data.p_pass_operate) {
          window.eventEmitter.$emit('EventMsgBank', data)
        }
        // 查询密码业务
        else if (('02' == data.p_pass_operate || '03' == data.p_pass_operate || '04' == data.p_pass_operate) && '00' == data.p_biz) {
          window.eventEmitter.$emit('EventPassUpdate', data)
        }
      } else {
        console.log('验密失败！')
        // window.globalUiKit.alert('验密失败', '失败原因：' + data.i_failurereason)
        window.globalUiKit.alert('身份验证未通过，业务信息查询失败')
      }
    }

    /********************************************************************************************
     *************************************** 视频业务接收逻辑 *************************************
     ********************************************************************************************/

    // 视频进线，代入卡照片等信息
    else if ('EventVideoRing' === message.event) {
      let data = message.data
      // 身份证正面照
      let frontIDCard = data.frontIDCard
      // 身份证反面照
      let reverseIDCard = data.reverseIDCard
      // 卡介质照片
      let mediaCard = data.mediaCard
      // 客户现场照片
      let cusScenePhoto = data.cusScenePhoto
      // 业务类型
      let businessType = data.businessType
      sessionStorage.setItem('businessType', businessType)
      if ('卡激活' == businessType) {
        window.eventEmitter.$emit('EventVideoTabActive')
      }
      setTimeout(function () {
        window.eventEmitter.$emit('EventVideoRing', data)
      }, 1000)
    }
    // 客户提交签名
    else if ('EventCusSignSubmit' === message.event) {
      let data = message.data
      // 客户签名照片
      let signPhoto = data.signPhoto
      window.eventEmitter.$emit('EventCusSignSubmit', data)
    }

    /**************************************** 卡激活 *************************************/
    // 收到拍照图片
    else if ('EventSnapSuccess' === message.event) {
      let data = message.data
      // 客户现场照
      let snapUrl = data.snapUrl
      window.eventEmitter.$emit('EventSnapSuccess', data)
    }
    // 收到短信验证码成功
    else if ('EventSmsCodeSuccess' === message.event) {
      window.eventEmitter.$emit('EventSmsCodeSuccess')
    }
    // 收到短信验证码失败
    else if ('EventSmsCodeFail' === message.event) {
      window.eventEmitter.$emit('EventSmsCodeFail')
    }
    // 收到客户确认的客户信息
    else if ('EventCusInfoConfirm' === message.event) {
      let data = message.data
      window.eventEmitter.$emit('EventCusInfoConfirm', data)
    }
    // 收到客户取消的客户信息
    else if ('EventCusInfoCancel' === message.event) {
      window.eventEmitter.$emit('EventCusInfoCancel')
    }
    // 收到客户设置交易密码超限或失败
    else if ('EventSetPassFail' === message.event) {
      window.eventEmitter.$emit('EventSetPassFail')
    }
    // 收到客户设置交易密码成功
    else if ('EventSetPassSuccess' === message.event) {
      let data = message.data
      let password = data.password
      window.eventEmitter.$emit('EventSetPassSuccess', data)
    }
    // 收到客户端提交的开通业务内容
    else if ('EventOpenBizSubmit' === message.event) {
      let data = message.data
      // ATM自助转账功能
      let item1 = data.item1
      // 单日转账限额（元）
      let item2 = data.item2
      // 互联网在线支付功能
      let item3 = data.item3
      window.eventEmitter.$emit('EventOpenBizSubmit', data)
    }
    // 收到客户端确认阅读告知书
    else if ('EventNotificationRead' === message.event) {
      window.eventEmitter.$emit('EventNotificationRead')
    }
    // 收到业务凭证确认
    else if ('EventBizCertConfrim' === message.event) {
      window.eventEmitter.$emit('EventBizCertConfrim')
    }

    /**************************************** 不动户 *************************************/
    // 客户交易密码失败
    else if ('EventCusPassFail' === message.event) {
      window.eventEmitter.$emit('EventCusPassFail')
    }
    // 客户交易密码成功
    else if ('EventCusPassSuccess' === message.event) {
      window.eventEmitter.$emit('EventCusPassSuccess')
    }
    // 客户确认业务凭证
    else if ('EventBizCertConfirm' === message.event) {
      window.eventEmitter.$emit('EventBizCertConfirm')
    }

    /********************************************************************************************
     ***************************************** 对公开户 ******************************************
     ********************************************************************************************/
    // 视频进线，代入经办人/法人等信息
    else if ('EventOpenHouseVideoRing' === message.event) {
      let data = message.data
      // 业务类型
      let businessType = data.businessType

      if ('对公开户' == businessType) {
        window.eventEmitter.$emit('EventOpenHouseVideoTabActive')
      }
      setTimeout(function () {
        window.eventEmitter.$emit('EventOpenHouseVideoRing', data)
      }, 1000)
    }
    // 收到抓拍的客户照片
    else if ('EventOpenVideoSnapSuccess' === message.event) {
      let data = message.data
      window.eventEmitter.$emit('EventOpenVideoSnapSuccess', data)
    }
    // 收到开立对公户性质客户信息确认
    else if ('EventCustInfoSuccess' === message.event) {
      window.eventEmitter.$emit('EventCustInfoSuccess')
    }
    // 收到签约客户信息确认
    else if ('EventSignInfoSuccess' === message.event) {
      window.eventEmitter.$emit('EventSignInfoSuccess')
    }
    // 收到法人拍照图片
    else if ('EventInviteSnapSuccess' === message.event) {
      let data = message.data
      window.eventEmitter.$emit('EventInviteSnapSuccess', data)
    }
    // 收到短信验证码成功
    else if ('EventMsgCodeSuccess' === message.event) {
      window.eventEmitter.$emit('EventMsgCodeSuccess')
    }
    // 收到短信验证码失败
    else if ('EventMsgCodeFail' === message.event) {
      window.eventEmitter.$emit('EventMsgCodeFail')
    }
    // 收到表单客户签名显示
    else if ('EventGetBizSignForm' === message.event) {
      let data = message.data
      window.eventEmitter.$emit('EventGetBizSignForm', data)
    }
    // 收到客户协议签名显示
    else if ('EventGetAgreementSign' === message.event) {
      let data = message.data
      window.eventEmitter.$emit('EventGetAgreementSign', data)
    }
    // 收到客户开户确认书签名显示
    else if ('EventGetSettleInfo' === message.event) {
      let data = message.data
      window.eventEmitter.$emit('EventGetSettleInfo', data)
    }
    // 收到交割信息确认
    else if ('EventSettleInfoConfirm' === message.event) {
      window.eventEmitter.$emit('EventSettleInfoConfirm')
    }
    // 收到电子凭证信息确认
    else if ('EventCreateVoucherConfirm' === message.event) {
      window.eventEmitter.$emit('EventCreateVoucherConfirm')
    }
    // 收到客户结束交易
    else if ('EventOpenVideoEndTransaction' === message.event) {
      window.eventEmitter.$emit('EventOpenVideoEndTransaction')
    }
    /*************************************************************************************************
     ************************************ 对公开户 - 手机银行 *******************************************
     ************************************************************************************************/
    // 视频进线，代入客户信息
    else if ('EventPhoneBankOpenRing' === message.event) {
      let data = message.data
      window.eventEmitter.$emit('EventPhoneBankOpenRingTabActive')
      setTimeout(function () {
        window.eventEmitter.$emit('EventPhoneBankOpenRing', data)
      }, 1000)
    }
    // 收到签名图片
    else if ('EventGetBizSign' === message.event) {
      let data = message.data
      window.eventEmitter.$emit('EventGetBizSign', data)
    }
    // 收到面签业务申请单
    else if ('EventGetBizSignForm' === message.event) {
      let data = message.data
      window.eventEmitter.$emit('EventGetBizSignForm', data)
    }
    /*************************************************************************************************
     ************************************ 卡激活 - 手机银行 *******************************************
     ************************************************************************************************/
    // 视频进线，代入客户信息
    else if ('EventPhoneBankCardRing' === message.event) {
      let data = message.data
      window.eventEmitter.$emit('EventPhoneBankCardRingTabActive')
      setTimeout(function () {
        window.eventEmitter.$emit('EventPhoneBankCardRing', data)
      }, 1000)
    }
    // 收到签名图片
    else if ('EventCardGetBizSign' === message.event) {
      let data = message.data
      window.eventEmitter.$emit('EventCardGetBizSign', data)
    }
    // 收到面签业务申请单
    else if ('EventCardGetBizSignForm' === message.event) {
      let data = message.data
      window.eventEmitter.$emit('EventCardGetBizSignForm', data)
    }
    /*************************************************************************************************
     ************************************ 理财风险评估 - 手机银行 *******************************************
     ************************************************************************************************/
    // 视频进线，代入客户信息
    else if ('EventPhoneBankFRARing' === message.event) {
      let data = message.data
      window.eventEmitter.$emit('EventPhoneBankFRARingTabActive')
      setTimeout(function () {
        window.eventEmitter.$emit('EventPhoneBankFRARing', data)
      }, 1000)
    }
    // 发送调查问卷结果(填完调查问卷之后)
    else if ('EventRiskQuestionResult' === message.event) {
      let data = message.data
      window.eventEmitter.$emit('EventRiskQuestionResult', data)
    }
    // 收到签名图片
    else if ('EventRiskGetBizSign' === message.event) {
      let data = message.data
      window.eventEmitter.$emit('EventRiskGetBizSign', data)
    }
    // 收到业务申请单
    else if ('EventRiskGetBizSignForm' === message.event) {
      let data = message.data
      window.eventEmitter.$emit('EventRiskGetBizSignForm', data)
    }

    /********************************************************************************************
     ***************************************** 暂未用到 ******************************************
     ********************************************************************************************/

    if (message.type == 'card') {
      let faceRecognition = document.getElementById('FaceRecognition-frame')
      if (faceRecognition) {
        faceRecognition.contentWindow.postMessage(message, '*')
      }
    }
    // 向坐席平台发送消息
    if (message.event === 'ewoUpdate') {
      var data = {
        'event': 'ewoUpdate'
      }
      window.top.postMessage(data, '*')
    }
    if (message.event === 'ewoAgentInfo') {
      let etsWorkorder = document.getElementById('ets-create-frame')
      if (etsWorkorder) {
        etsWorkorder.contentWindow.postMessage(message, '*')
      }
    }
    if (message.event === 'ewoCall') {
      var ewoCallData = {
        'event': 'ewoCall',
        'ewoCallData': {
          number: message.data.number
        }
      }
      window.top.postMessage(ewoCallData, '*')
      let etsWorkorder = document.getElementById('ets-create-frame')
      if (etsWorkorder) {
        etsWorkorder.contentWindow.postMessage(message, '*')
      }
    }
    if (message.event === 'loadEvent') {
      let etsWorkorder = document.getElementById('ets-create-frame')
      if (etsWorkorder) {
        etsWorkorder.contentWindow.postMessage(message, '*')
      }
    }
    if (message.event === 'getEditList') {
      var getEditListData = {
        'event': 'getEditList',
        'getEditListData': {
          listLength: message.data.listLength
        }
      }
      window.top.postMessage(getEditListData, '*')
      let etsWorkorder = document.getElementById('ets-create-frame')
      if (etsWorkorder) {
        etsWorkorder.contentWindow.postMessage(message, '*')
      }
    }

    if (message.system === 'Platform2OCRM') {
      window.window.eventEmitter.$emit('EventPlatform2OCRM', message)
    } else if (message.event === 'EventAgentLogout') {
      let crmFrame = document.getElementById('crmFrame')
      if (crmFrame) {
        crmFrame.contentWindow.postMessage(message, '*')
      }
    } else if (message.event === 'EventChatAccept') {
      // console.log('EventChatAccept,message:' + JSON.stringify(message))
      window.window.eventEmitter.$emit('EventChatAccept', message)
    } else if (message.event === 'EventChangeChatRecord') {
      console.log('EventChangeChatRecord,message:' + JSON.stringify(message))
      let etsWorkorder = document.getElementById('ets-create-frame')
      if (etsWorkorder) {
        etsWorkorder.contentWindow.postMessage(message, '*')
      }
      window.window.eventEmitter.$emit('EventChangeChatRecord', message)
    } else if (message.event === 'sendEndSessionToBusiness') {
      console.log('sendEndSessionToBusiness,message:' + JSON.stringify(message))
      let etsWorkorder = document.getElementById('ets-create-frame')
      if (etsWorkorder) {
        etsWorkorder.contentWindow.postMessage(message, '*')
      }
      window.window.eventEmitter.$emit('sendEndSessionToBusiness', message)
    }
    // 进线地区
    if (message.r_areacode) {
    }
    // 振铃事件
    if (message.stateid === 'EventRinging') {
      window.eventEmitter.$emit('personalEventRinging', message)
    }
    // 会话建立
    if (message.event === 'EventCallEstablished') {
      window.eventEmitter.$emit('overseasEstablish', message)
      Utils.log.info('会话建立')
      Utils.log.info(message)
      Utils.log.info('会话建立获取的银行号：')
      Constants.company.i_bankNo = message.data.callInfo.bankNo
    }
    // 话后处理
    if (message.agentstatus === 'AfterCallWork') {
      // 置外呼三方验密标识为false
      window.eventEmitter.$on('outboundDialing', function (event) {
        event.data = false
      })
      // 话后处理验证标识
      window.eventEmitter.$emit('clearFlag')
    }
    // 外呼振铃状态
    if (message.event === 'EventDialing') {
      Utils.log.info('外呼振铃状态')
      Utils.log.info(message)
      window.eventEmitter.$emit('outboundDialing', message)
    }
    // 对公业务
    if (message.p_verifytype === '01' && message.i_verifyflag === '01') {
      Utils.log.info('company success')
      Constants.company.i_verifyflag = message.i_verifyflag
      Utils.log.info(Constants.company.i_verifyflag)
      Constants.company.p_callingStatus = message.p_callingStatus
      Utils.log.info(Constants.company.p_callingStatus)
      Constants.company.p_cert_num = message.p_cert_num
      Utils.log.info(Constants.company.p_cert_num)
      Constants.company.i_operatorid = message.i_operatorid
      Utils.log.info(Constants.company.i_operatorid)
      Constants.company.i_bankNo = message.i_bankNo
      window.eventEmitter.$emit('companyIvr', message)
    } else if (message.p_verifytype === '01' && message.i_verifyflag !== '01') {
      // 验证失败提示信息
      window.eventEmitter.$emit('companyErrorTip', message)
    } else if (message.p_verifytype === '02' && message.i_verifyflag === '01') {
      // 对私业务
      Utils.log.info(message.i_verifyflag)
      window.eventEmitter.$emit('personalIvr', message)
    } else if (message.p_verifytype === '02' && message.i_verifyflag !== '01') {
      window.eventEmitter.$emit('personalErrorTip', message)
    }

    // 服务历史跳转电子工单
    if (message.event === 'EventCreateEtsHistory') {
      window.eventEmitter.$emit('historyEsatblish', message)
      Utils.log.info('服务历史电子工单监听事件')
    }
    // 知识搜索事件
    if (message.event === Constants.events.knowSearch) {
      let userData = message.data
      if (userData) {
        console.log('知识库监听事件' + JSON.stringify(userData))
        // knowSearch(userData)
        window.eventEmitter.$emit('knowSearchVal', message)
      }
    }
  },

  /*************************************************************************************************
   *************************************** 共享集成 *************************************************
   ************************************************************************************************/

  /**
   * 共享客户、账户信息
   *
   * @param sessionId
   */
  shareCusAndAccInfo: function () {
    let data = {
      'event': 'EventCusAndAccInfo',
      'data': {
        'personInfo': Constants.personInfo,
        'companyInfo': Constants.companyInfo,
        'lossInfo': Constants.lossInfo
      }
    }
    console.log('传给工单客户信息：' + data)
    let etsFrame = document.getElementById('ets-create-frame')
    if (etsFrame) {
      etsFrame.contentWindow.postMessage(data, '*')
    }
  },

  /**
   * 发起验密
   *
   * @param userdata
   */
  verifyPass: function (userdata) {
    let data = {
      'event': 'EventVerifyPass',
      'sessionId': Constants.ModelChat.sid,
      'data': userdata
    }
    window.parent.postMessage(data, '*')
  },

  /*************************************************************************************************
   *************************************** 视频业务发送 *********************************************
   ************************************************************************************************/

  /**
   * 发起意愿核实成功
   *
   * @param sessionId
   */
  sendSnap: function () {
    let data = {
      'event': 'EventSnap',
      'sessionId': Constants.ModelChat.sid
    }
    window.parent.postMessage(data, '*')
  },

  /**
   * 发起意愿核实成功
   *
   * @param sessionId
   */
  sendWillingVerifySuccess: function (cusObj) {
    let data = {
      'event': 'EventWillingVerifySuccess',
      'sessionId': Constants.ModelChat.sid,
      'data': cusObj
    }
    window.parent.postMessage(data, '*')
  },

  /**
   * 发起重新签名
   *
   * @param sessionId
   */
  sendReSign: function () {
    let data = {
      'event': 'EventReSign',
      'sessionId': Constants.ModelChat.sid
    }
    window.parent.postMessage(data, '*')
  },

  /**
   * 提交业务凭证，办理成功
   *
   * @param sessionId
   */
  sendBizSuccess: function () {
    let data = {
      'event': 'EventBizSuccess',
      'sessionId': Constants.ModelChat.sid
    }
    window.parent.postMessage(data, '*')
  },

  /**
   * 提交业务凭证，办理失败
   *
   * @param sessionId
   */
  sendBizFail: function () {
    let data = {
      'event': 'EventBizFail',
      'sessionId': Constants.ModelChat.sid
    }
    window.parent.postMessage(data, '*')
  },

  /**
   * 发起结束交易
   *
   * @param sessionId
   */
  sendEndTransaction: function () {
    let data = {
      'event': 'EventEndTransaction',
      'sessionId': Constants.ModelChat.sid
    }
    window.parent.postMessage(data, '*')
  },

  /**************************************** 卡激活 *************************************/

  /**
   * 发送短信验证码
   *
   * @param sessionId
   */
  sendSmsCode: function (cusTel, code) {
    let data = {
      'event': 'EventSmsCodeSend',
      'sessionId': Constants.ModelChat.sid,
      'data': {
        'tel': cusTel,
        'code': code
      }
    }
    window.parent.postMessage(data, '*')
  },

  /**
   * 发送更新后的客户信息给客户确认
   *
   * @param sessionId
   */
  sendUpdateCusInfo: function (cusObj) {
    let data = {
      'event': 'EventUpdateCusInfo',
      'sessionId': Constants.ModelChat.sid,
      'data': cusObj
    }
    window.parent.postMessage(data, '*')
  },

  /**
   * 发送设置交易密码
   *
   * @param sessionId
   */
  sendSetPass: function () {
    let data = {
      'event': 'EventSetPass',
      'sessionId': Constants.ModelChat.sid
    }
    window.parent.postMessage(data, '*')
  },

  /**
   * 发送重新选择开通业务
   *
   * @param sessionId
   */
  sendReOpenBiz: function () {
    let data = {
      'event': 'EventReOpenBiz',
      'sessionId': Constants.ModelChat.sid
    }
    window.parent.postMessage(data, '*')
  },

  /**
   * 发送确认开通业务
   *
   * @param sessionId
   */
  sendOpenBizConfirm: function () {
    let data = {
      'event': 'EventOpenBizConfirm',
      'sessionId': Constants.ModelChat.sid
    }
    window.parent.postMessage(data, '*')
  },

  /**
   * 发送业务确认单
   *
   * @param sessionId
   */
  sendBizConfirmForm: function (failReason) {
    let data = {
      'event': 'EventBizConfirmForm',
      'sessionId': Constants.ModelChat.sid,
      'data': {
        'message': failReason
      }
    }
    window.parent.postMessage(data, '*')
  },

  /**
   * 发送提交业务确认单，成功
   *
   * @param sessionId
   */
  sendBizFormSuccess: function () {
    let data = {
      'event': 'EventBizFormSuccess',
      'sessionId': Constants.ModelChat.sid
    }
    window.parent.postMessage(data, '*')
  },

  /**
   * 发送提交业务确认单，失败
   *
   * @param sessionId
   */
  sendBizFormFail: function (failReason) {
    let data = {
      'event': 'EventBizFormFail',
      'sessionId': Constants.ModelChat.sid,
      'data': {
        'message': failReason
      }
    }
    window.parent.postMessage(data, '*')
  },

  /**
   * 发送业务凭证和签名
   *
   * @param sessionId
   */
  sendBizCertAndSign: function (certObj) {
    let data = {
      'event': 'EventBizCertAndSign',
      'sessionId': Constants.ModelChat.sid,
      'data': certObj
    }
    window.parent.postMessage(data, '*')
  },


  /**************************************** 不动户 *************************************/
  /**
   * 发起客户签名
   *
   * @param sessionId
   */
  sendCusSign: function () {
    let data = {
      'event': 'EventCusSign',
      'sessionId': Constants.ModelChat.sid
    }
    window.parent.postMessage(data, '*')
  },

  /**
   * 发起确认签名
   *
   * @param sessionId
   */
  sendConfirmSign: function () {
    let data = {
      'event': 'EventConfirmSign',
      'sessionId': Constants.ModelChat.sid
    }
    window.parent.postMessage(data, '*')
  },

  /**
   * 发起业务凭证
   *
   * @param sessionId
   */
  sendBizCert: function (bizObj) {
    let data = {
      'event': 'EventBizCert',
      'sessionId': Constants.ModelChat.sid,
      'data': bizObj
    }
    window.parent.postMessage(data, '*')
  },

  /***************************************** 对公开户 ******************************************/

  /**
   * 抓拍客户照片
   *
   * @param sessionId
   */
  sendOpenVideoSnap: function () {
    let data = {
      'event': 'EventOpenVideoSnap',
      'sessionId': Constants.ModelChat.sid
    }
    window.parent.postMessage(data, '*')
  },

  /**
   * 对公开户信息审核
   *
   * @param sessionId
   */
  sendCustInfoNext: function () {
    let data = {
      'event': 'EventCustInfoNext',
      'sessionId': Constants.ModelChat.sid
    }
    window.parent.postMessage(data, '*')
  },

  /**
   * 开立对公户性质客户信息更新确认
   *
   */
  sendOpenVideoUpdateCusInfo: function (custObj) {
    let data = {
      'event': 'EventOpenVideoUpdateCusInfo',
      'sessionId': Constants.ModelChat.sid,
      'data': custObj
    }
    window.parent.postMessage(data, '*')
  },

  /**
   * 跳转签约信息界面
   *
   */
  sendSignInfoNext: function () {
    let data = {
      'event': 'EventSignInfoNext',
      'sessionId': Constants.ModelChat.sid
    }
    window.parent.postMessage(data, '*')
  },

  /**
   * 签约客户信息更新确认
   *
   */
  sendSignInfoToCustomer: function (signObj) {
    let data = {
      'event': 'EventOpenVideoUpdateSignInfo',
      'sessionId': Constants.ModelChat.sid,
      'data': signObj
    }
    window.parent.postMessage(data, '*')
  },

  /**
   * 跳转开户意愿确认
   *
   */
  sendOpenAccountNext: function () {
    let data = {
      'event': 'EventOpenAccountNext',
      'sessionId': Constants.ModelChat.sid
    }
    window.parent.postMessage(data, '*')
  },

  /**
   * 抓拍法人照片
   *
   */
  sendVideoInviteSnap: function () {
    let data = {
      'event': 'EventInviteSnap',
      'sessionId': Constants.ModelChat.sid
    }
    window.parent.postMessage(data, '*')
  },

  /**
   * 发送邀请短信
   *
   */
  sendJoinConferenceInvitation: function () {
    let data = {
      'event': 'EventsendMsgInvitation',
      'sessionId': Constants.ModelChat.sid
    }
    window.parent.postMessage(data, '*')
  },

  /**
   * 跳转苏州农商银行开立单位银行结算账户申请书
   *
   */
  sendBizSignFormNext: function () {
    let data = {
      'event': 'EventBizSignFormNext',
      'sessionId': Constants.ModelChat.sid
    }
    window.parent.postMessage(data, '*')
  },

  /**
   * 将表单发送给客户
   *
   */
  sendBizSignFormToCustomer: function (obj) {
    let data = {
      'event': 'EventBizSignFormToCustomer',
      'sessionId': Constants.ModelChat.sid,
      'data': obj
    }
    window.parent.postMessage(data, '*')
  },

  /**
   * 重新发起表单签名发送给客户
   *
   */
  sendResBizSignFormToCustomer: function () {
    let data = {
      'event': 'EventResBizSign',
      'sessionId': Constants.ModelChat.sid
    }
    window.parent.postMessage(data, '*')
  },

  /**
   * 跳转协议签名区域
   *
   */
  sendAgreementNext: function () {
    let data = {
      'event': 'EventAgreementNext',
      'sessionId': Constants.ModelChat.sid
    }
    window.parent.postMessage(data, '*')
  },

  /**
   * 协议签名发送给客户
   *
   */
  sendAgreementSignToCustomer: function (obj) {
    let data = {
      'event': 'EventAgreementSignToCustomer',
      'sessionId': Constants.ModelChat.sid,
      'data': obj
    }
    window.parent.postMessage(data, '*')
  },

  /**
   * 重新发起协议签名发送给客户
   *
   */
  sendResAgreementToCustomer: function () {
    let data = {
      'event': 'EventResAgreement',
      'sessionId': Constants.ModelChat.sid
    }
    window.parent.postMessage(data, '*')
  },

  /**
   * 跳转法人承诺页面
   *
   */
  sendSignatureConfirmNext: function (obj) {
    let data = {
      'event': 'EventSignatureConfirmNext',
      'sessionId': Constants.ModelChat.sid,
      'data': obj
    }
    window.parent.postMessage(data, '*')
  },

  /**
   * 跳转开户确认书页面
   *
   */
  sendSettleInfoNext: function () {
    let data = {
      'event': 'EventSettleInfoNext',
      'sessionId': Constants.ModelChat.sid
    }
    window.parent.postMessage(data, '*')
  },

  /**
   * 发送客户开户确认书重新签名
   *
   */
  sendResSettleInfo: function () {
    let data = {
      'event': 'EventResSettleInfo',
      'sessionId': Constants.ModelChat.sid
    }
    window.parent.postMessage(data, '*')
  },

  /**
   * 跳转交割信息页面
   *
   */
  sendSignatureNext: function () {
    let data = {
      'event': 'EventSignatureNext',
      'sessionId': Constants.ModelChat.sid
    }
    window.parent.postMessage(data, '*')
  },

  /**
   * 交割信息推送给客户
   *
   */
  sendSignatureToCustomerNext: function (obj) {
    let data = {
      'event': 'EventSignatureToCustomerNext',
      'sessionId': Constants.ModelChat.sid,
      'data': obj
    }
    window.parent.postMessage(data, '*')
  },

  /**
   * 交割信息提交
   *
   */
  sendSubmitSettleInfo: function () {
    let data = {
      'event': 'EventSubmitSettleInfo',
      'sessionId': Constants.ModelChat.sid
    }
    window.parent.postMessage(data, '*')
  },

  /**
   * 生成电子凭证
   *
   */
  sendCreateVoucher: function () {
    let data = {
      'event': 'EventCreateVoucher',
      'sessionId': Constants.ModelChat.sid
    }
    window.parent.postMessage(data, '*')
  },

  /**
   * 将凭证发送给客户
   *
   */
  sendCreateVoucherToCustomer: function (obj) {
    let data = {
      'event': 'EventCreateVoucherToCustomer',
      'sessionId': Constants.ModelChat.sid,
      'data': obj
    }
    window.parent.postMessage(data, '*')
  },

  /**
   * 提交电子凭证成功
   *
   */
  sendSubmitCreateVoucher: function () {
    let data = {
      'event': 'EventSubmitCreateVoucher',
      'sessionId': Constants.ModelChat.sid
    }
    window.parent.postMessage(data, '*')
  },

  /**
   * 提交电子凭证失败
   *
   */
  sendSubmitCreateVoucherFail: function () {
    let data = {
      'event': 'sendSubmitCreateVoucherFail',
      'sessionId': Constants.ModelChat.sid
    }
    window.parent.postMessage(data, '*')
  },

  /**
   * 关闭交易
   *
   */
  sendOpenVideoEndTransaction: function () {
    let data = {
      'event': 'EventOpenVideoEndTransaction',
      'sessionId': Constants.ModelChat.sid
    }
    window.parent.postMessage(data, '*')
  },

  /*************************************************************************************************
   ************************************ 对公开户 - 手机银行 *******************************************
   ************************************************************************************************/
  /**
   * 发起签名
   *
   */
  sendEventResBizSign: function () {
    let data = {
      'event': 'EventResBizSign',
      'sessionId': Constants.ModelChat.sid
    }
    window.parent.postMessage(data, '*')
  },
  /**
   * 跳转到面签业务申请单
   *
   */
  sendEventBizCertFormStep: function () {
    let data = {
      'event': 'EventBizCertFormStep',
      'sessionId': Constants.ModelChat.sid
    }
    window.parent.postMessage(data, '*')
  },
  /**
   * 面签业务申请单-拒绝
   *
   */
  sendEventBizCertFail: function (reason) {
    let data = {
      'event': 'EventBizCertFail',
      'sessionId': Constants.ModelChat.sid,
      'data': reason
    }
    window.parent.postMessage(data, '*')
  },
  /**
   * 面签业务申请单-通过
   *
   */
  sendEventBizCertSuccess: function () {
    let data = {
      'event': 'EventBizCertSuccess',
      'sessionId': Constants.ModelChat.sid
    }
    window.parent.postMessage(data, '*')
  },

  /*************************************************************************************************
   ************************************ 卡激活 - 手机银行 *******************************************
   ************************************************************************************************/
  /**
   * 发起签名
   *
   */
  sendEventCardResBizSign: function () {
    let data = {
      'event': 'EventCardResBizSign',
      'sessionId': Constants.ModelChat.sid
    }
    window.parent.postMessage(data, '*')
  },
  /**
   * 跳转到面签业务申请单
   *
   */
  sendEventCardFormStep: function () {
    let data = {
      'event': 'EventCardFormStep',
      'sessionId': Constants.ModelChat.sid
    }
    window.parent.postMessage(data, '*')
  },
  /**
   * 面签业务申请单-拒绝
   *
   */
  sendEventCardFail: function (reason) {
    let data = {
      'event': 'EventCardFail',
      'sessionId': Constants.ModelChat.sid,
      'data': reason
    }
    window.parent.postMessage(data, '*')
  },
  /**
   * 面签业务申请单-通过
   *
   */
  sendEventCardSuccess: function () {
    let data = {
      'event': 'EventCardSuccess',
      'sessionId': Constants.ModelChat.sid
    }
    window.parent.postMessage(data, '*')
  },

  /*************************************************************************************************
   ************************************ 风险测评 - 手机银行 *******************************************
   ************************************************************************************************/
  /**
   * 发送能力评估问卷申请
   *
   */
  sendBrowseQuestionnaire: function () {
    let data = {
      'event': 'EventBrowseQuestionnaire',
      'sessionId': Constants.ModelChat.sid
    }
    window.parent.postMessage(data, '*')
  },
  /**
   * 发起签名
   *
   */
  sendEventRiskResBizSign: function () {
    let data = {
      'event': 'EventRiskResBizSign',
      'sessionId': Constants.ModelChat.sid
    }
    window.parent.postMessage(data, '*')
  },
  /**
   * 跳转到面签业务申请单
   *
   */
  sendEventRiskFormStep: function () {
    let data = {
      'event': 'EventRiskFormStep',
      'sessionId': Constants.ModelChat.sid
    }
    window.parent.postMessage(data, '*')
  },
  /**
   * 风评业务申请单-拒绝
   *
   */
  sendEventRiskFail: function (reason) {
    let data = {
      'event': 'EventRiskFail',
      'sessionId': Constants.ModelChat.sid,
      'data': reason
    }
    window.parent.postMessage(data, '*')
  },
  /**
   * 风评业务申请单-通过
   *
   */
  sendEventRiskSuccess: function () {
    let data = {
      'event': 'EventRiskSuccess',
      'sessionId': Constants.ModelChat.sid
    }
    window.parent.postMessage(data, '*')
  },


}

/*************************************************************************************************
 *************************************** 暂未用到 *************************************************
 ************************************************************************************************/

function sendMsgToFrame(href) {
  var data = {}
  if (href == '#system') {
    var inboundFrame = document.getElementById('idx-system-frame')
    if (!Agent.getCurrentAgent().agentId) {
      setTimeout(function () {
        if (inboundFrame) {
          data = {
            'event': 'EventChangeToSystemTab',
            'data': {
              'agentId': Agent.getCurrentAgent().agentId,
              'tenantId': Agent.getCurrentAgent().tenantId
            }
          }
          console.log(JSON.stringify(data))
          inboundFrame.contentWindow.postMessage(data, '*')
        }
      }, 3000)
    } else {
      data = {
        'event': 'EventChangeToSystemTab',
        'data': {
          'agentId': Agent.getCurrentAgent().agentId,
          'tenantId': Agent.getCurrentAgent().tenantId
        }
      }
      if (inboundFrame) {
        inboundFrame.contentWindow.postMessage(data, '*')
      }
    }
  }
  else if (href == '#workorder') {
    var workorderFrame = document.getElementById('idx-workorder-frame')
    data = {
      'event': 'EventPassAgentInfoToWorkOrder',
      'data': {
        'agentId': Agent.getCurrentAgent().userId,
        'agentName': Agent.getCurrentAgent().agentName,
        'resources': Agent.getCurrentAgent().resources
      }
    }
    if (workorderFrame) {
      workorderFrame.contentWindow.postMessage(data, '*')
    }
  }
  else if (href == '#workordermanage') {
    var workordermanageFrame = document.getElementById('idx-workordermanage-frame')
    data = {
      'event': 'EventPassAgentInfoToWorkOrder',
      'data': {
        'agentId': Agent.getCurrentAgent().userId,
        'agentName': Agent.getCurrentAgent().agentName,
        'resources': Agent.getCurrentAgent().resources
      }
    }
    if (workordermanageFrame) {
      workordermanageFrame.contentWindow.postMessage(data, '*')
    }
  }
  else if (href == '#omni') {
    var chatDIVHeight = $('.chat-nav').height()
    $('#omniContent').css('height', 'calc(100% - ' + chatDIVHeight + 'px)')
    $(window).trigger('resize')
  }
  else if (href == '#leaveMsg') {
    var leaveMsgFrame = document.getElementById('idx-leaveMsg-frame')
    data = {
      'event': 'EventPassAgentInfoToLeaveMsg',
      'data': {
        'agentId': Agent.getCurrentAgent().agentId,
        'agentName': Agent.getCurrentAgent().agentName,
        'deptGroupCode': Agent.getCurrentAgent().deptGroupCode,
        'leavemsgTypes': Agent.getCurrentAgent().leavemsgTypes
      }
    }
    if (leaveMsgFrame) {
      console.log(JSON.stringify(data))
      leaveMsgFrame.contentWindow.postMessage(data, '*')
    }
  }
}
